/*
 * @(#) BaseUIActivity.java 2013-3-29 下午5:40:16
 * Copyright 2013 Rockwell Automation, Inc. All rights reserved.
 * Rockwell Automation PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */package com.osi.mes.base.control;

import java.awt.Dimension;

import com.datasweep.compatibility.client.Response;
import com.datasweep.compatibility.ui.ActivityControl;
import com.datasweep.compatibility.ui.BorderStyle;
import com.datasweep.compatibility.ui.ComboBox;
import com.datasweep.compatibility.ui.ContentAlignment;
import com.datasweep.compatibility.ui.DateTimePicker;
import com.datasweep.compatibility.ui.DateTimePickerFormat;
import com.datasweep.compatibility.ui.Edit;
import com.datasweep.compatibility.ui.FlatButton;
import com.datasweep.compatibility.ui.FlatLabel;
import com.datasweep.compatibility.ui.GroupBox;
import com.datasweep.compatibility.ui.Panel;
import com.datasweep.compatibility.ui.TabControl;
import com.datasweep.compatibility.ui.TabPage;
import com.datasweep.compatibility.ui.Time;
import com.datasweep.compatibility.ui.grid.ColumnDefinition;
import com.datasweep.plantops.swing.ControlDock;
import com.datasweep.plantops.swing.ImageHolder;
import com.osi.mes.constants.IUIConstants;
import com.rockwell.activity.ItemDescriptor;
import com.rockwell.ftpc.framework.common.DateTimeUtils;
import com.rockwell.ftpc.framework.common.StringUtils;
import com.rockwell.smartedit.SmartEdit;

public abstract class BaseUIActivity extends ActivityControl implements IUIConstants {
	
	protected FlatButton createFlatButton(String btnName,String btnText){
		FlatButton flatButton = new FlatButton();
		flatButton.setName(btnName);
		flatButton.setPreferredSize(new Dimension(DEFAULT_BTN_WIDTH, DEFAULT_BTN_HEIGHT));
		flatButton.setFont(DEFAULT_FONT);
		flatButton.setText(btnText);
		return flatButton;
	}
	
	protected ColumnDefinition createColumnDefinition(String heading){
		ColumnDefinition columnDefinition = new ColumnDefinition();
		columnDefinition.setHeading(heading);
		columnDefinition.setWidth(75);
		columnDefinition.setControlType(null);
		return columnDefinition;
	}
	
	protected FlatButton createFlatButton(String btnName, String btnText,ImageHolder imageHolder){
		FlatButton flatButton = createFlatButton(btnName, btnText);
		flatButton.setImageHolder(imageHolder);
		return flatButton;
	}
	
	protected FlatLabel createFlatLabel(String labelName,String labelText){
		FlatLabel flatLabel = new FlatLabel();
		flatLabel.setName(labelName);
		flatLabel.setText(StringUtils.isNull(labelText)?null:labelText+":");
		flatLabel.setFont(DEFAULT_FONT);
		flatLabel.setPreferredSize(new Dimension(DEFAULT_LABEL_WIDTH, DEFAULT_LABEL_HEIGHT));
		flatLabel.setTextAlign(ContentAlignment.MIDDLERIGHT);
		return flatLabel;
	}
	
	protected ComboBox createComboBox(String comboBoxName){
		ComboBox comboBox = new ComboBox();
		comboBox.setName(comboBoxName);
		comboBox.setPreferredSize(new Dimension(DEFAULT_EDIT_WIDTH, DEFAULT_EDIT_HEIGHT));
		return comboBox;
	}
	
	protected Edit createEdit(String editName){
		Edit edit = new Edit();
		edit.setName(editName);
		edit.setFont(DEFAULT_FONT);
		edit.setPreferredSize(new Dimension(DEFAULT_EDIT_WIDTH, DEFAULT_EDIT_HEIGHT));
		return edit;
	}
	
	protected SmartEdit createSmartBoolean(String editName){
		SmartEdit smartEdit = new SmartEdit();
		smartEdit.setLabelVisible(false);
		smartEdit.setBorderStyle(BorderStyle.NONE);
		smartEdit.setName(editName);
		smartEdit.setPreferredSize(new Dimension(DEFAULT_EDIT_WIDTH, DEFAULT_EDIT_HEIGHT));
		smartEdit.setEditorSupportClass("com.datasweep.plantops.property.editor.BooleanPropertyEditor");
		smartEdit.setValue(false);
		return smartEdit;
	}
	
	protected SmartEdit createSmartNumber(String editName){
		SmartEdit smartEdit = new SmartEdit();
		smartEdit.setLabelVisible(false);
		smartEdit.setBorderStyle(BorderStyle.NONE);
		smartEdit.setName(editName);
		smartEdit.setPreferredSize(new Dimension(DEFAULT_EDIT_WIDTH, DEFAULT_EDIT_HEIGHT));
		smartEdit.setEditorSupportClass("com.datasweep.plantops.property.editor.NumberPropertyEditor");
		smartEdit.setValue(0);
		return smartEdit;
	}
	
	protected DateTimePicker createDateTimePicker(String editName){
		DateTimePicker dateTimePicker = new DateTimePicker();
		dateTimePicker.setFormat(DateTimePickerFormat.LONG);
		dateTimePicker.setName(editName);
		dateTimePicker.setPreferredSize(new Dimension(DEFAULT_EDIT_WIDTH, DEFAULT_EDIT_HEIGHT));
		return dateTimePicker;
	}
	
	protected Panel createPanel(String panelName,int controlDock,int width, int height){
		Panel panel = createPanel(panelName, controlDock);
		panel.setPreferredSize(new Dimension(width, height));
		return panel;
	}
	
	protected GroupBox createGroupBox(String groupBoxName)
	{
		GroupBox groupBox = new GroupBox();
		groupBox.setName(groupBoxName);
		groupBox.setDock(ControlDock.FILL);
		return groupBox;
	}
	
	protected TabControl createTabControl(String tabControlName)
	{
		TabControl tabControl = new TabControl();
		tabControl.setName(tabControlName);
		tabControl.setDock(ControlDock.FILL);
		return tabControl;
	}
	
	protected TabPage createTabPage(String tabPageName)
	{
		TabPage tabPage = new TabPage();
		tabPage.setName(tabPageName);
		tabPage.setDock(ControlDock.FILL);
		return tabPage;
	}
	
	protected GroupBox createGroupBox(String groupBoxName,int controlDock,int width, int height)
	{
		GroupBox groupBox = new GroupBox();
		groupBox.setName(groupBoxName);
		groupBox.setDock(controlDock);
		groupBox.setPreferredSize(new Dimension(width, height));
		return groupBox;
	}
	
	protected Panel createPanel(String panelName,int controlDock){
		Panel panel = new Panel();
		panel.setName(panelName);
		panel.setBorderStyle(BorderStyle.NONE);
		panel.setDock(controlDock);
		return panel;
	}
	
	protected String formatDate(Time time){
		return DateTimeUtils.formatDate(time, "yyyy-MM-dd HH:mm:ss");
	}
	
	protected Time getTrxTime(){
		return getFunctions().getDBTime();
	}

	@Override
	public ItemDescriptor[] configurationDescriptors() {return null;}

	@Override
	public Response activityExecute() {return null;}

	@Override
	protected void configurationItemSet(String arg0, Object arg1) {}

	@Override
	protected void configurationLoaded() {}

	@Override
	public String getActivityDescription() {return null;}

	@Override
	protected String[] getActivityEvents() {return null;}

	@Override
	public ItemDescriptor[] inputDescriptors() {return null;}

	@Override
	protected void inputItemSet(String arg0, Object arg1) {}

	@Override
	public ItemDescriptor[] outputDescriptors() {return null;}

	@Override
	protected void shutdown() {}

	@Override
	protected void startup() {}

	@Override
	protected void updateAfterExecute() {}

}
